package com.leyou.item.web;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.SkuDTO;
import com.leyou.item.dto.SpuDTO;
import com.leyou.item.dto.SpuDetailDTO;
import com.leyou.item.service.SkuService;
import com.leyou.item.service.SpuDetailService;
import com.leyou.item.service.SpuService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("goods")
public class GoodsController {

    private final SpuService spuService;

    private final SpuDetailService detailService;

    private final SkuService skuService;

    public GoodsController(SpuService SpuService, SpuDetailService detailService, SkuService skuService) {
        this.spuService = SpuService;
        this.detailService = detailService;
        this.skuService = skuService;
    }
    //GET分页查询spu
    @GetMapping("spu/page")
    public ResponseEntity<PageDTO<SpuDTO>> goodsPageQuery(@RequestParam("page")Integer page,
                                                          @RequestParam("rows")Integer rows){
        return ResponseEntity.ok(this.spuService.goodsPageQuery(page,rows));

    }
    //GET根据id批量查询sku 实现
    @GetMapping("/sku/list")
    public ResponseEntity<List<SkuDTO>> querySkuByIds(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(this.skuService.querySkuByIds(ids));
    }
    //GET根据spuID查询sku的集合
    @GetMapping("sku/of/spu")
    public ResponseEntity<List<SkuDTO>> querySkuBySpuId(@RequestParam("id")Long id){
        return ResponseEntity.ok(this.skuService.querySkuBySpuId(id));
    }









}